{extend name="base"}
{block name="title"}临时战绩详情{/block}
{block name="head"}
<script src="__STATIC__/common/avalon.mobile-2.2.9.min.js"></script>
<style>
.border-table tbody th {text-align:right; width:70px; padding:2px 5px;}
td.avatar {padding:0 10px; line-height:0px;}
td.avatar img {width:44px; height:44px; line-height:44px;}
</style>
{/block}
{block name="body"}
<body class="mainbody ms-controller" ms-controller="GameDetail">
<form>
<!--导航栏-->
<div class="location">
  <a href="javascript:history.back(-1);" class="back"><i class="iconfont icon-up"></i><span>返回上一页</span></a>
  <a href="{:url('index/home')}" class="home"><i class="iconfont icon-home"></i><span>首页</span></a>
  <i class="arrow iconfont icon-arrow-right"></i>
  <span>临时战绩详情</span>
</div>
<!--/导航栏-->
<!--列表-->
<div class="table-container">
  <table class="border-table ltable" style="width:auto" data-auto="0">
    <tr><th>#{{@DataAll[0].RoomID}}</th><td ms-for="(k,v) in (@UserMap)">玩家[{{k}}]</td></tr>
    <tr><th>玩家头像</th><td ms-for="(k,v) in @UserMap" class="avatar"><img ms-attr="{src:v.Avatar?v.Avatar:'__STATIC__/houtai/images/dface.png'}" /></td></tr>
    <tr><th>游戏标识</th><td ms-for="(k,v) in @UserMap"><a target="_blank" ms-attr="{href:@URL_USER_DETAIL+v.UserID}">{{v.GameID}}</a></td></tr>
    <tr><th>游戏昵称</th><td ms-for="(k,v) in @UserMap">{{v.NickName|escape}}</td></tr>
    <tr><th>合计输赢</th><td ms-for="(k,v) in @UserMap" ms-css="{color:v.Total<0?'green':'red'}">{{v.Total}}</td></tr>
    <!--ms-for:(a,b) in @DataAll-->
    <tr><th>[{{b.Cnt}}]{{b.Time}}</th><td ms-for="(c,d) in b.DataMap" ms-css="{color:d.Score<0?'green':'red'}">{{d.GameID=='_'?'':d.Score}}</td></tr>
    <!--ms-for-end:-->
  </table>
</div>
<!--/列表-->
</form>
<script>
avalon.ready(function () {

  var listRecord = {:json_encode($listRecord, JSON_UNESCAPED_UNICODE)};
  var listAvatar = {:json_encode($listAvatar, JSON_UNESCAPED_UNICODE)};
  var UserMap = [];

  avalon.each(listRecord, function (a, b) {
    avalon.each(b.DataRaw, function (c, d) {
      var found = 0;
      avalon.each(UserMap, function (e, f) {
        if (f.GameID == d[0]) {
          found = 1;
          return false;
        }
      });
      if (found == 0) {
        UserMap.push({GameID:d[0],NickName:d[2]});
      }
    });
  });

  avalon.each(listRecord, function (a, b) {
    var DataMap = [];
    avalon.each(UserMap, function (c, d) {  // 按照人数对齐
      var found = -1;
      avalon.each(b.DataRaw, function (e, f) {
        if (d.GameID == f[0]) {
          found = e;
          return false;
        }
      });
      DataMap.push({
        GameID: found == -1 ? '_' : b.DataRaw[found][0],
        Score: found == -1 ? '_' : b.DataRaw[found][1]
      });
      d.Total = typeof(d.Total) == 'undefined' ? 0 : d.Total;
      d.Total += found == -1 ? 0 : b.DataRaw[found][1] * 1;
    });
    delete b.DataRaw;
    b.DataMap = DataMap;
  });
  
  // 填充头像
  avalon.each(UserMap, function (a, b) {
    avalon.each(listAvatar, function (c, d) {
      if (b.GameID == d.GameID) {
        b.Avatar = d.Avatar;
        b.UserID = d.UserID;
        return false;
      }
    });
  });

  var vm = avalon.define({
    $id: "GameDetail",
    URL_USER_DETAIL: "{:url('user.detail/index')}?UserID=",
    UserMap: UserMap,
    DataAll: listRecord
  });
  avalon.scan(document.body);
  
  avalon.log(vm.UserMap.toJSON());
  avalon.log(vm.DataAll.toJSON());
});
</script>
</body>
{/block}